main.controller('dashBroadCtrl', ['$scope','$rootScope','$timeout','NoticeServ','tools', function($scope,$rootScope,$timeout,NoticeServ,tools) {
	console.log('dashBroad.js');

	$timeout(function(){
		NoticeServ.$broadcast('GLOBAL_CATEGORY_CHANGE_EV', "/");
	},1000);

	
	
	NoticeServ.$on($scope,'LOGIN_EV',function(){
		$rootScope.$broadcast('GLOBAL_CATEGORY_CHANGE_EV', "/");
	});
	
	$scope.cardsconfig = {
		cardTitle:[''],
		icin:''

	}
	$scope.configline = {
		title: '全网类目销售额走势图',
		option: {
			tooltip: {
				trigger: 'axis',
				axisPointer: {
					type: 'shadow'
				},
				formatter: function(params) {
					
					var str = '<div style = "text-align: left;">' + params[0].name + ' 销售额</div>';

					for (var i = 0; i < params.length; i++) {
						str += '<div style = "text-align: left;padding-left:10px;"><span style="width:10px;height:10px;display:inline-block;border-radius:50%;background:'+params[i].color+'"></span>  ' + params[i].seriesName + ' : ' + tools.bigNumFormat(params[i].data) + '</div>';
					}

					return str;
				}
			},
			grid: {
				left: 80
			},
			legend: {
				data: ['总和', '天猫', '淘宝','天猫国际','全球购'],
				x: 25,
				y: 15
			},
			xAxis: {
				data: [],
				axisLabel: {
                    //rotate: 50,
                    show: true
                }
            },
            yAxis: [{
            	type: 'value',
            	axisLabel: {
            		formatter: function(value, index) {
            			var len = String(value).length;

            			if (value < 10000) {
            				return value;
            			}

            			switch (len) {
            				case 5:
            				return (value / 10000) + '万';
            				case 6:
            				return (value / 10000) + '万';
            				case 7:
            				return (value / 10000) + '万';
            				case 8:
            				return (value / 10000) + '万';
            				case 9:
            				return (value / 100000000) + '亿';
            				case 10:
            				return (value / 100000000) + '亿';
            				case 11:
            				return (value / 100000000) + '亿';
            				case 12:
            				return (value / 100000000) + '亿';
            			}

            			return value;
            		}
            	}
            }],
            series: [
	            {
	            	name: '总和',
	            	type: 'line',
	            	data: []
	            },
	            {
	            	name: '天猫',
	            	type: 'line',
	            	data: []
	            },	            
	            {
	            	name: '淘宝',
	            	type: 'line',
	            	data: [],
	            	label: {
	            		normal: {
	            			formatter: function(value) {
	            				return '元';
	            			}
	            		},
	            		emphasis: function(value) {
	            			return '33';
	            		}
	            	}
	            },
	            {
	            	name: '天猫国际',
	            	type: 'line',
	            	data: []
	            }, {
	            	name: '全球购',
	            	type: 'line',
	            	data: []
	            }
            ]
        },
        get:function(scope,myChart,catName){
        	myChart.clear();
        	myChart.showLoading();
        	this.option.xAxis.data = [];
        	this.option.series[0].data = [];
        	this.option.series[1].data = [];
        	this.option.series[2].data = [];
        	this.option.series[3].data = [];
        	this.option.series[4].data = []
        	var $option = this.option;
        	tools.$get({
                url: '/marketconditions/statistic/getCategoryStatisticIndex.htm',
                data: {
                    catName: catName
                }
            }).then(function(resp){
            	console.log('78')
            	console.log(resp);
            	var dim = "sellMoney";
            	
                for (var i = 0; i < resp.value.length; i++) {
                    $option.xAxis.data.push(resp.value[i].date.split(' ')[0].slice(5, 20));
                    $option.series[0].data.push(resp.value[i][dim]);
                    $option.series[1].data.push(resp.value[i]['t' + dim[0].toUpperCase() + dim.slice(1)]);
                    $option.series[2].data.push(resp.value[i]['c' + dim[0].toUpperCase() + dim.slice(1)]);
                    $option.series[3].data.push(resp.value[i]['thk' + dim[0].toUpperCase() + dim.slice(1)]);
                    $option.series[4].data.push(resp.value[i]['g' + dim[0].toUpperCase() + dim.slice(1)]);
                }
                myChart.setOption($option);
                myChart.hideLoading();   

            },function(errResp){

            });
                
        },
        handel: function() {

        }
    };
}]);
